package com.kushuigu;

import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.stereotype.Component;

@Component
@Aspect

public class MyAdvice {
    @Pointcut("execution(* com.kushuigu.dao.BookDao.update())")
    public void pt1(){}

    @Pointcut("execution(* com.kushuigu.dao.BookDao.select())")
    public void pt2(){}
    @Before("pt1()")
    public void before(){
        System.out.println("before");
    }
    @After("pt1()")
    public void after(){
        System.out.println("after");
    }
    @Around("pt1()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("around before");
        proceedingJoinPoint.proceed();
        System.out.println("around after");
    }

    @Around("pt2()")
    public Object aroundSelect(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("around before");
        Object o = proceedingJoinPoint.proceed();
        System.out.println("around after");
        return o;
    }
    @AfterReturning("pt1()")
    public void afterReturning() {
        System.out.println("afterReturning");
    }
    @AfterThrowing("pt1()")
    public void afterThrowing() {
        System.out.println("afterThrowing");
    }
}
